$(function(){
  // 发送Ajax请求
  $('.btn_login').on('click',function(){
    var username = $('input[name=username]').val();
    var password = $('input[name=password]').val();
    if(!username){
      mui.toast('请输入用户名');
      return
    }
    if(!password){
      mui.toast('请输入密码');
      return
    }
    $.ajax({
      url:'/user/login',
      type:'post',
      data:{
        username:username,
        password:password
      },
      success:function(info){
        console.log(info);
        if(info.error){
          mui.toast(info.message);
        }
        if(info.success){
          // 获取地址栏中传来的backUrl
          var search=location.search;

          if(search.indexOf('backUrl')===-1){
            没有传backUrl
            location.href="user.html"
          }else{
            // 传backUrl
            location.href=search.replace('?backUrl=','');
          }
        }
      }
    })
  })
})